package cn.jianyongjie.controller;

import cn.jianyongjie.domain.User;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCollapser;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
* @Description: TODO
* @Author: JianYongJie
* @Version: 1.0
* @Date:  2022/5/30 16:12
*/
@RestController
public class OrderController {

    @Autowired
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "underpinning") //
    @GetMapping("/orderById/{id}")
    public User orderById(@PathVariable("id") Long id){

        // 设置跳转用户的路径
        String url = "http://user-server/userById/"+id;;
        // 发送http请求
        return restTemplate.getForObject(url,User.class);

    }


    public User underpinning(@PathVariable("id") Long id){
        return new User(id,"网络连接异常",1);
    }

}
